Skip to content

Conversation

ludvigz
Copy link
Member

@ludvigz ludvigz commented Nov 13, 2026

Purpose

The Community page triggered one extra database query per published build to load its components, an N+1 problem: showing 20 builds took about 21 queries, growing with the number of builds. This PR batches those lookups so the query count stays constant.

Changes

  • Add a per-request DataLoader (createBuildPartsLoader in resolvers.ts) that fetches the parts of all requested builds in one parameterized query.
  • Create a new loader for every request in index.ts, so results are not cached between requests.
  • Add the dataloader dependency.
  • Add buildPartsBatching.test.ts, which runs the real builds { parts } query through Apollo and checks the results and the number of queries. Update the Build.parts test in resolvers.test.ts to use the loader.

Loading 20 builds with their parts now takes 2 queries (one for the builds, one for all their parts) instead of 21.

Related issues

Closes #100

Verification

  • npm test: all 85 tests pass. The new tests show exactly 2 queries for 1, 5, 20 and 100 builds, that every build gets its own parts in category order, that shared parts are fetched once, and that no parts query runs when no build has parts.
  • npx tsc --noEmit and npx eslint .: clean.

Screenshots

Not applicable

Checklist

  • I have reviewed my own changes.
  • The changes meet the linked issue's acceptance criteria, where applicable.
  • I have verified the changes and recorded the results above.
  • I have added or updated tests where needed.
  • I have updated documentation where needed.
  • I have included screenshots for visual changes, or marked them not applicable.

@ludvigz ludvigz self-assigned this Nov 13, 2026
@ludvigz ludvigz requested a review from a team as a code owner November 13, 2026 19:37
@ludvigz ludvigz linked an issue Nov 13, 2026 that may be closed by this pull request
4 tasks
Copy link
Member

@oscarog oscarog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

@oscarog oscarog merged commit 22653aa into dev Nov 13, 2026
@oscarog oscarog deleted the 100-improve-community-backend-query-performance branch November 13, 2026 22:11
Sign in to join this conversation on GitHub.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve Community backend query performance
2 participants